package com.onlinefurnitureshop.management.controller;

import java.sql.Date;
import java.util.List;

import com.onlinefurnitureshop.management.model.Role;
import com.onlinefurnitureshop.management.model.Users;
import com.onlinefurnitureshop.management.service.RoleService;
import com.onlinefurnitureshop.management.service.UsersService;

public class UsersAction extends BaseAction{
	private UsersService usersService;
	private List<Users> userList;
	private List<Role> roleList;
	private Users user;
	private RoleService roleService;
	private Long id;
	
	

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public List<Users> getUserList() {
		return userList;
	}

	public void setUserList(List<Users> userList) {
		this.userList = userList;
	}

	public UsersService getUsersService() {
		return usersService;
	}

	public void setUsersService(UsersService usersService) {
		this.usersService = usersService;
	}
	
	
	
	public Users getUser() {
		return user;
	}

	public void setUser(Users user) {
		this.user = user;
	}

	
	
	public RoleService getRoleService() {
		return roleService;
	}

	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}
	

	public List<Role> getRoleList() {
		return roleList;
	}

	public void setRoleList(List<Role> roleList) {
		this.roleList = roleList;
	}

	public String list(){
		
		userList = usersService.findAll();
		return "userList";
	}
	
	public String showCreateForm(){
		roleList = roleService.findAll();
		id=null;
		user = new Users();
		return "userEdit";
	}
	
	public String create(){
		Date createTime = new Date(System.currentTimeMillis());
		user.setCreateTime(createTime);
		usersService.createUser(user);
		return "listAction";
	}
	
	public String showUpdateForm(){
		System.out.println(id);
		roleList = roleService.findAll();
		user = usersService.findOne(id);
		return "userEdit";
	}
	public String update(){
		usersService.updateUser(user);
		return "listAction";
	}
	
	public String showDeleteForm(){
		System.out.println(id);
		return "userDelete";
	}
	public String delete(){
		usersService.deleteUser(id);
		return "listAction";
	}

}
